﻿using UnityEngine;
using Cysharp.Threading.Tasks;


namespace Core.Runtime
{
    public static partial class AssetManager
    {
        /// <summary>
        /// 检查资源版本（可等待）
        /// </summary>
        public static UniTask<VersionCheckResult> CheckVersion()
        {
            UniTaskCompletionSource<VersionCheckResult> tcs = new UniTaskCompletionSource<VersionCheckResult>();
            CheckVersion((result => { tcs.TrySetResult(result); }));
            return tcs.Task;
        }

        /// <summary>
        /// 加载预制体并实例化，会自行将Handler绑定至实例化出的游戏物体上（可等待）
        /// </summary>
        public static UniTask<GameObject> InstantiateAsync(string prefabName, Transform parent = null)
        {
            UniTaskCompletionSource<GameObject> tcs = new UniTaskCompletionSource<GameObject>();
            InstantiateAsync(prefabName, (go => { tcs.TrySetResult(go); }), parent);
            return tcs.Task;
        }
    }
}